# Python 趣味编程：第 6 章
#  例題 6.2 扑克牌和扑克牌表
# --------------------------
# 程序名: 06-cards.py
# P110  程序6.8, 程序6.9, 程序6.10

from dataclasses import dataclass
import random

@dataclass
class Card:
    suit: str
    rank: int

    def print(self):                # 显示扑克牌
        print("{}.{}".format(self.suit, self.rank))

class CardTable:
    def __init__(self): # 扑克牌表的初始化
        self.deck = []
        self.hand = []

def set_cards(deck): # 把所有的扑克牌都放在牌组里
    for suit in ["spade", "heart", "club", "diamond"]:
        for rank in range(13):
            deck.append(Card(suit, rank))
    random.shuffle(deck)

table = CardTable()
set_cards(table.deck)
for x in range(5):
    card = table.deck.pop()  # 从手牌中取出一张牌
    table.hand.append(card)  # 添加到手牌中

for card in table.hand:      # 取出手上所有的扑克牌
    card.print()             # 显示牌
